package com.qfedu.dao;

import com.qfedu.model.Stage;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface StageDao {

    //根据pid查询
    @Select("select * from Stage where pid=#{pid} and status=1")
    List<Stage> findByPid(int pid);

    //添加表
    @Insert("insert into stage (sname,starttime,endtime,pid,updatetime,status) values(" +
            "#{sname},#{starttime},#{endtime},#{pid},#{updatetime},#{status})")
    void addStage(Stage stage);

    //删除表
    @Update("update stage set status = 0 where sid = #{sid}")
    void deleteStage(String sid);

    //修改表

    @Update("update stage set sname=#{sname},starttime=#{starttime},endtime=#{endtime}," +
            "pid=#{pid},updatetime=#{updatetime},status=#{status} where sid = #{sid}")
    void updateStage(Stage stage);

    //添加所有
    @Results(id = "findAllMap", value = {
            @Result(column = "sid",property = "sid"),
            @Result(column = "sname",property = "sname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
            @Result(column = "pid",property = "project",
                    one = @One(select = "com.qf.dao.ProjectDao.findByPid",fetchType = FetchType.EAGER))
    })
    @Select("select * from stage where status = 1")
    List<Stage> findAll();
}
